import React from 'react'
import { HomeConfig } from 'services/config'
import services from 'services'
import './index.less'
import { Form, Input, Button, Layout, } from 'antd';
import { useNavigate } from 'react-router-dom';
import store from 'store'
import { changeLogin } from 'store/reducer/app/action'


export default function Login(props) {
    const navigate = useNavigate();

    const onFinish = (values) => {
        console.log('values: ', values);
        localStorage.setItem('token', 'dev')
        store.dispatch(changeLogin(true))
        navigate('/admin_index',{replace:true})
    };
    

    const onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };

    const test = async (params) => {
        const { code, data } = await services({
            url: HomeConfig.Test,
            method: "post",
            data: { ...params }
        });
        if (code === "200" && data) {
            console.log(data)
        }
    };

    return (
        <Layout className="login">

        <Form
            name="normal_login"
            className="login-form"
            initialValues={{
                remember: true,
            }}
            onFinish={onFinish}
        >
            <h2>LOGIN</h2>

            <div className='label_title'>USERNAME</div>
            <Form.Item
                name="username"
                rules={[
                    {
                        required: true,
                        message: 'Please input your account.',
                    },
                ]}
            >
                <Input type="text" />
            </Form.Item>
            <div className='label_title'>PASSWORD</div>
            <Form.Item
                name="password"
                rules={[
                    {
                        required: true,
                        message: 'Please input your password.',
                    },
                ]}
            >
                <Input
                    type="password"
                />
            </Form.Item>
            <Form.Item>
                <Button type="primary" htmlType="submit" className="login-form-button">
                    SUBMIT
                </Button>
            </Form.Item>
        </Form>


    </Layout>
    )
}
